public class Solution1144 {
    public int movesToMakeZigzag(int[] nums) {
        int last=nums[0],count=0;
        for (int i=1;i<nums.length;i++){
            if (i%2==1){
                if (nums[i]>=last){
                    count+=nums[i]-last+1;
                    last=last-1;
                }else{
                    last=nums[i];
                }
            }else{
                if (nums[i]<=last){
                    count+=last-nums[i]+1;
                }
                last=nums[i];
            }
        }
        int ans=count;
        count=0;
        last=nums[0];
        for (int i=1;i<nums.length;i++){
            if (i%2==0){
                if (nums[i]>=last){
                    count+=nums[i]-last+1;
                    last=last-1;
                }else{
                    last=nums[i];
                }
            }else{
                if (nums[i]<=last){
                    count+=last-nums[i]+1;
                }
                last=nums[i];
            }
        }
        return Math.min(count,ans);
    }

    public static void main(String[] args) {
        System.out.println(new Solution1144().movesToMakeZigzag(new int[]{2,7,10,9,8,9}));
    }
}
